using System;
using System.Collections.Specialized;
using System.Web.UI;
using Portal.Core.Binding;
using Portal.Core.Binding.FormBuilder;
using Portal.Data.Webparts;

public partial class Webparts_GenericEditor : EditorPart, IPostBackDataHandler
{
    #region IPostBackDataHandler Members

    public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
    {
        return true;
    }

    public void RaisePostDataChangedEvent()
    {
    }

    #endregion

    public override void InitEditor(WebpartConfig config)
    {
        BuildContext context = new BuildContext();
        context.BindData = !IsPostBack;
        var buildForm = Builder.BuildForm(config.GetType(), context);
        buildForm.ID = "frmWebParts";
        phContent.Controls.Add(buildForm);
        context.OnDataBind();
        if (!IsPostBack)
        {
            Binder.SetData(phContent.Controls[0], config, new BindContext());
        }
        base.InitEditor(config);
    }

    protected override void OnLoad(EventArgs e)
    {
        Page.RegisterRequiresPostBack(this);
    }

    public override void ApplyChange(WebpartConfig config)
    {
        Binder.GetData(config, phContent.Controls[0], new BindContext());
        base.ApplyChange(config);
    }
}